package cn.com.eado.uwallpaper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.com.eado.uwallpaper.bean.MeiziBean;
import cn.com.eado.uwallpaper.utils.TUtil;

/**
 * Created by lcy on 2015/12/23.
 */
public class MeiziAdapter extends RecyclerView.Adapter<MeiziAdapter.GalleryViewHolder> {

    private Context mContext;
    List<MeiziBean.ResEntity.WallpaperEntity>  mData;

    public MeiziAdapter(Context context,List<MeiziBean.ResEntity.WallpaperEntity> category) {
        mContext = context;
        mData=category;
    }



    @Override
    public GalleryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=View.inflate(mContext,R.layout.meizi_item,null);
        GalleryViewHolder viewHolder=new GalleryViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final GalleryViewHolder holder, int position) {
//        Picasso.with(mContext).load(mData.get(position).getCover()).into(holder.image);//只能是静态图片；；
        MeiziBean.ResEntity.WallpaperEntity wallpaper=mData.get(position);
        Glide.with(mContext).load(wallpaper.getPreview()).diskCacheStrategy(DiskCacheStrategy. SOURCE).into(holder.image_meizi);
        String url=wallpaper.getImg();//大图所在地址；
        holder.image_meizi.setTag(url);
        holder.image_meizi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TUtil.show(mContext,"点击了图片，进入大图的activity");
//                Intent intent = new Intent(mContext, ItemActivity.class);
//                intent.putExtra("url", (String) (holder.image_meizi.getTag()));
//                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class GalleryViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.image_meizi)
        ImageView image_meizi;

        public GalleryViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
